package com.ycsj.goldmedalnewconcept.common.adapter;


import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.makeramen.roundedimageview.RoundedImageView;
import com.ycsj.common.image.ImageUtil;
import com.ycsj.common.view.dialog.AlertDialogUtil;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.common.activity.HelpDetailsActivity;
import com.ycsj.goldmedalnewconcept.common.activity.LivingActivity;
import com.ycsj.goldmedalnewconcept.common.bean.LivingInfo;

import java.util.List;


/**
 * 直播列表的适配器
 * Created by Administrator on 2018/6/29 0029.
 */

public class LivingRvAdapter extends BaseQuickAdapter<LivingInfo.DataBean, BaseViewHolder> {

    private Context context;

    public LivingRvAdapter(Context context, int layoutResId, @Nullable List<LivingInfo.DataBean> data) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, final LivingInfo.DataBean item) {
        //头像
        RoundedImageView ivHead = helper.getView(R.id.iv_head);
        ImageUtil.displayImage(context, ivHead, item.getIMG_URL());

        //直播名称
        TextView tvName = helper.getView(R.id.tv_name);
        tvName.setText(item.getTITLE());

        //直播状态,对应三种状态,直播中,未开始,已结束,teacher_state_living,teacher_state_living_no_start,teacher_state_living_over
        TextView tvState = helper.getView(R.id.tv_state);
        if (item.getSTATUS() == 0) {
            //未开始
            tvState.setText("未开始");
            tvState.setBackgroundResource(R.drawable.teacher_state_living_no_start);
        } else if (item.getSTATUS() == 1) {
            //直播中
            tvState.setText("直播中");
            tvState.setBackgroundResource(R.drawable.teacher_state_living);
        } else if (item.getSTATUS() == 2) {
            tvState.setText("已结束");
            tvState.setBackgroundResource(R.drawable.teacher_state_living_over);
        }

        //直播时间
        TextView tvTime = helper.getView(R.id.tv_time);
        tvTime.setText(item.getBEGIN_TIME());

        //主讲人
        TextView tvPeople = helper.getView(R.id.tv_people);
        tvPeople.setText(item.getSPEAKER());

        //条目的布局
        LinearLayout llItem = helper.getView(R.id.ll_item);
        llItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (item.getSTATUS() == 0) {
                    //未开始
                    AlertDialogUtil.showAlertDialog(true, context, item.getTITLE() +
                            ",直播时间为" + item.getBEGIN_TIME() + "，请稍后观看", new AlertDialogUtil.onListener() {
                        @Override
                        public void onClickOk() {

                        }

                        @Override
                        public void onClickDismiss() {

                        }
                    });
                } else if (item.getSTATUS() == 1) {
                    //直播中，跳转到直播界面
                    Intent intent = new Intent(context, LivingActivity.class);
                    intent.putExtra("data", item);
                    context.startActivity(intent);
                } else if (item.getSTATUS() == 2) {
                    //已结束
                    if (item.getSTATUS2() == 2 && (!TextUtils.isEmpty(item.getPROTOCOL_URL3()))) {
                        //完成上传跳转webview播放视频
                        Intent intent = new Intent(context, HelpDetailsActivity.class);
                        intent.putExtra("url", item.getPROTOCOL_URL3());
                        intent.putExtra("title", item.getTITLE());
                        context.startActivity(intent);

                    } else {
                        //尚未上传视频地址
                        AlertDialogUtil.showAlertDialog(true, context, "直播已结束，程序GG正在加急审核，请稍后观看录播（一般会审核1-3个工作日）", new AlertDialogUtil.onListener() {
                            @Override
                            public void onClickOk() {

                            }

                            @Override
                            public void onClickDismiss() {

                            }
                        });
                    }
                }

            }
        });
    }
}
